package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxManage;
import com.ruoyi.system.mapper.RxManageMapper;
import com.ruoyi.system.service.IRxManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 总后台管理员Controller
 *
 * @author hjf
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/hmk/manage")
public class RxManageController extends BaseController {
    @Autowired
    private IRxManageService rxManageService;

    @Autowired
    private RxManageMapper rxManageMapper;

    /**
     * 查询总后台管理员列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxManage rxManage) {
        startPage();
        List<RxManage> list = rxManageService.selectRxManageList(rxManage);
        return getDataTable(list);
    }


    @GetMapping("/ListSimple")
    @PermitAll
    public AjaxResult ListSimple(RxManage rxManage) {
        return AjaxResult.success(rxManageMapper.selectRxManageListSimple(rxManage));
    }


    @GetMapping("/getRxManageByGroupBy16")
    @PermitAll
    public AjaxResult getRxManageByGroupBy16(RxManage rxManage) {
        return AjaxResult.success(rxManageMapper.getRxManageByGroupBy16(rxManage));
    }


    /**
     * 导出总后台管理员列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:manage:export')")
    //@Log(title = "总后台管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxManage rxManage) {
        List<RxManage> list = rxManageService.selectRxManageList(rxManage);
        ExcelUtil<RxManage> util = new ExcelUtil<RxManage>(RxManage.class);
        util.exportExcel(response, list, "总后台管理员数据");
    }

    /**
     * 获取总后台管理员详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:manage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxManageService.selectRxManageById(id));
    }

    /**
     * 新增总后台管理员
     */
    @PreAuthorize("@ss.hasPermi('hmk:manage:add')")
    //@Log(title = "总后台管理员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxManage rxManage) {
        return toAjax(rxManageService.insertRxManage(rxManage));
    }

    /**
     * 修改总后台管理员
     */
    @PreAuthorize("@ss.hasPermi('hmk:manage:edit')")
    //@Log(title = "总后台管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxManage rxManage) {
        return toAjax(rxManageService.updateRxManage(rxManage));
    }

    /**
     * 删除总后台管理员
     */
    @PreAuthorize("@ss.hasPermi('hmk:manage:remove')")
    //@Log(title = "总后台管理员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxManageService.deleteRxManageByIds(ids));
    }
}
